<template>
	<view class="container">
		<!-- 顶部选项卡 -->
		<view class="swiper-tab dis-flex box-align-center flex-y-center">
			<block v-for="(item, index) in tabList" :key="index">
				<view class="swiper-tab-item flex-box" :class="{ on: type == item.value }" :data-current="item.value" @tap="swichNav">{{ item.text }}({{ item.total }})</view>
			</block>
		</view>
		<!-- 团队总人数 -->
		<view class="widget-people f-28 col-9">团队总人数：{{ dealer.team_num }}人</view>
		<!-- 我的团队列表 -->
		<scroll-view :scroll-y="true" @scrolltolower="triggerDownLoad" :style="{ height: swiperHeight + 'px' }">
			<view class="widget-list b-f" v-if="list.data.length">
				<view class="widget__detail dis-flex flex-x-between" v-for="(item, index) in list.data" :key="index">
					<view class="detail__left dis-flex flex-y-center">
						<view class="user-avatar"><image :src="item.user.avatarUrl"></image></view>
						<view class="user-info dis-flex flex-dir-column flex-x-center">
							<view class="user-nickName f-28">{{ item.user.nickName }}</view>
							<view class="user-time col-9 f-24">{{ item.create_time }}</view>
						</view>
					</view>
					<view class="detail__right dis-flex flex-dir-column flex-x-center flex-y-center">
						<view class="detail__money">
							<text class="f-24">￥</text>
							<text class="f-34">{{ item.user.expend_money }}</text>
						</view>
						<view class="detail__member f-22" v-if="item.dealer">{{ item.dealer.team_num }}个成员</view>
					</view>
				</view>
				<!-- 没有更多 -->
				<view v-if="list.data.length && !isLoading && no_more" class="no-more f-30">亲, 没有更多了</view>
			</view>
			<!-- 没有记录 -->
			<view class="yoshop-notcont" v-if="!list.data.length && !isLoading">
				<text class="iconfont icon-wushuju"></text>
				<text class="cont">亲，暂无团队记录哦</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isLoading: true,
			type: 'team',
			page: 1,
			no_more: false,
			list: { data: [] },
			tabList: [],
			swiperHeight: null,
			dealer: {}
		};
	},
	onLoad() {
		this.getTeamList();
	},
	methods: {
		/**
		 * 获取我的团队列表
		 */
		getTeamList(isNextPage, page) {
			this.$get(
				this.$api.getUserDealerTeamLists,
				{
					type: this.type,
					page: page || 1
				},
				res => {
					// 创建页面数据
					const data = this.createData(res.data, isNextPage);
					this.dealer = data.dealer;
					this.isLoading = data.isLoading;
					this.list = data.list;
					this.setting = data.setting;
					this.tabList = data.tabList;
					// console.log(this.createData(result.data, isNextPage));
				}
			);
		},
		/**
		 * 创建页面数据
		 */
		createData(data, isNextPage) {
			data['isLoading'] = false;
			// 列表数据
			let dataList = this.list;
			if (isNextPage == true && typeof dataList !== 'undefined') {
				data.list.data = dataList.data.concat(data.list.data);
			}
			// 团队总人数
			// data['team_total'] = data.dealer.first_num;
			// 导航栏数据
			data['tabList'] = [
				{
					value: 'team',
					text: '全部',
					total: data.dealer.team_num
				},
				{
					value: 'first',
					text: '一级团队',
					total: data.dealer.first_num
				},
				{
					value: 'second',
					text: '二级团队',
					total: data.dealer.second_num
				},
				{
					value: 'third',
					text: '三级团队',
					total: data.dealer.third_num
				}
			];
			// 设置swiper的高度
			this.setSwiperHeight();
			return data;
		},
		/**
		 * 设置swiper的高度
		 */
		setSwiperHeight() {
			// 获取系统信息(拿到屏幕宽度)
			let systemInfo = wx.getSystemInfoSync();
			let tapHeight = uni.upx2px(82); // tap高度
			let peopleHeight = uni.upx2px(65); // people高度
			let swiperHeight = systemInfo.windowHeight - tapHeight - peopleHeight; // swiper高度
			this.swiperHeight = swiperHeight;
		},
		/**
		 * 点击tab切换
		 */
		swichNav(e) {
			this.type = e.target.dataset.current;
			this.list = { data: [] };
			this.page = 1;
			this.no_more = false;
			this.isLoading = true;
			this.$nextTick(() => {
				this.getTeamList();
			});
		},
		/**
		 * 下拉到底加载数据
		 */
		triggerDownLoad() {
			// console.log(this.data.list);
			// 已经是最后一页
			if (this.page >= this.list.last_page) {
				this.no_more = true;
				return false;
			}
			this.getTeamList(true, ++this.page);
		}
	}
};
</script>

<style>
page {
	background: #fff;
}

/* 选项卡 */

.swiper-tab {
	width: 100%;
	text-align: center;
	height: 80rpx;
	background-color: #fff;
	border-bottom: 1px solid #eee;
}

.swiper-tab .swiper-tab-item {
	/* width: 33.333333%; */
	height: 100%;
	font-size: 28rpx;
	color: #777;
	display: flex;
	justify-content: center;
	align-items: center;
	box-sizing: border-box;
	border-bottom: 2px solid #ffffff00;
}

.swiper-tab .on {
	color: #786cff;
	border-bottom: 2px solid #786cff;
}

/* 设置scroll-view容器高度 */

.widget-list,
.yoshop-notcont {
	height: 100.1%;
}

/* 团队人数 */

.widget-people {
	padding: 15rpx 25rpx;
	height: 65rpx;
	box-sizing: border-box;
	background: #f7f7f7;
}

/* 提现明细列表 */

.widget-list {
	padding: 10rpx 20rpx 40rpx 20rpx;
	box-sizing: border-box;
}

.widget__detail {
	padding: 20rpx 15rpx;
	box-sizing: border-box;
	font-size: 28rpx;
	border-bottom: 1rpx solid #e7e7e7;
}

.widget__detail .user-avatar {
	margin-right: 16rpx;
}

.widget__detail .user-avatar image {
	display: block;
	width: 100rpx;
	height: 100rpx;
	border: 4rpx solid #fff;
	border-radius: 50%;
}

.widget__detail .user-info {
	height: 100%;
}

.widget__detail .user-nickName {
	margin-bottom: 8rpx;
}

.widget__detail .detail__member {
	background-color: #786cff;
	color: #fff;
	padding: 2rpx 15rpx;
	border-radius: 6rpx;
	margin-top: 10rpx;
}
</style>
